import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 启动类
 * 获取Parse类解析的结果，传给Listener执行判断
 * 根据Listener结果打印输出
 *
 * @author Administrator
 */
public class Game {

    /**
     * beforeChess：棋子移动前位置【列】【行】
     * curChess：棋子移动后位置【列】【行】
     * flag【行】【列】
     * wangChess 将（）
     */
    public static int[] beforeChess = new int[3];
    public static int[] curChess = new int[3];
    public static int[][] flag = new int[][]{
            {1, 2, 3, 4, 5, 4, 3, 2, 1},
            {0, 0, 0, 0, 0, 0, 0, 0, 0},
            {0, 6, 0, 0, 0, 0, 0, 6, 0},
            {7, 0, 7, 0, 7, 0, 7, 0, 7},
            {0, 0, 0, 0, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, 0, 0, 0, 0},
            {77, 0, 77, 0, 77, 0, 77, 0, 77},
            {0, 66, 0, 0, 0, 0, 0, 66, 0},
            {0, 0, 0, 0, 0, 0, 0, 0, 0},
            {11, 22, 33, 44, 55, 44, 33, 22, 11}
    };
    public static String GAME_FILE = "res/input2.txt";

    public static void main(String[] args) {

        Parse parse = new Parse();
        Listener listener = new Listener();


        PrintStream ps = null;
        try {
            ps = new PrintStream("res/test2.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        //把创建的打印输出流赋给系统。即系统下次向 ps输出
        System.setOut(ps);


        parse.init();
        int nChess = parse.nChess;
        //棋谱规则
        String rule;

        //棋子代号
        int mark;

        //例：存炮二平五的二和五
        int[] moveChess = new int[3];

        //平移、进、退
        String direction;

        for (int i = 1; i < nChess + 1; i++) {
            System.out.print(i + ". ");

            //一条棋谱规则
            rule = parse.filterMap.get(i);

            //棋子代号
            mark = parse.wordPars(i, rule);

            //移动步数
            moveChess = parse.pawnPars(rule);

            //移动方向
            direction = parse.moveDirection(rule);


            //翻转棋盘
            listener.overturnChess(flag);


            //获取移动前位置
            listener.movePrep(flag, mark, moveChess[0]);


            //获取移动后位置
            listener.moveLocation(mark, moveChess[1] - 1, direction);

            //移动
            listener.moveToTarget(flag, mark);

        }

    }

}